package com.example.consumer;

import com.example.dto.MessageDto;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class FanoutConsumer3 {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("fanout.queue.3"),
            exchange = @Exchange(name = "fanout.exchange", type = "fanout")
    ))
    public void receiveFanoutMessage(String messageStr, Channel channel, Message message) throws IOException {
        log.info("消费者3 接收到广播消息: {}", messageStr);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); // 批量确认

    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("fanout.queue.3.object"),
            exchange = @Exchange(name = "fanout.exchange", type = "fanout")
    ))
    public void receiveFanoutObject(MessageDto messageDto, Channel channel, Message message) throws IOException {
        log.info("消费者3 接收到广播对象消息: {}", messageDto);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); // 批量确认

    }
}